#ifndef __maindefs
#define __maindefs

#include <p18cxxx.h>
#include "error_handler.h"

// PIC function flag
#define SENSORS_PIC 0
#define LOCONET_PIC !SENSORS_PIC

// Message type definitions
#define MSGT_TIMER0 10
#define MSGT_TIMER1 11
#define MSGT_ADC 12
#define MSGT_MAIN1 20
#define	MSGT_OVERRUN 30
#define MSGT_UART_DATA 31
#define MSGT_LOCONET_MSG 32
#define MSGT_I2C_DBG 41
#define	MSGT_I2C_DATA 40
#define MSGT_I2C_RQST 42
#define MSGT_I2C_MASTER_SEND_COMPLETE 43
#define MSGT_I2C_MASTER_SEND_FAILED 44
#define MSGT_I2C_MASTER_RECV_COMPLETE 45
#define MSGT_I2C_MASTER_RECV_FAILED 46
#define MSGT_I2C_REG_RQST 47
#define MSGT_SENSOR_DATA 50

// Custom errors
#define ERR_MSG_LOST -10

#if defined(__18F45J10)

// Shorthand definitions
#define I2C_SCL PORTCbits.SCL
#define I2C_SDA PORTCbits.SDA

// LED Bits
#define TMR0LED LATBbits.LATB0
#define ERRORLED LATBbits.LATB1
#define I2CLED LATBbits.LATB2
#define MSGQLED LATBbits.LATB3
#define TMR1LED LATBbits.LATB4
#define ADCLED LATBbits.LATB5

#elif defined(__18F2680)

#if LOCONET_PIC
// LED Bits
#define A0LED LATCbits.LATC0
#define A1LED LATCbits.LATC1
#define A2LED LATCbits.LATC2

#define DBG0 LATBbits.LATB3
#define DBG1 LATBbits.LATB4
#define DBG2 LATBbits.LATB5 // This LED doesn't work
#define MSGQLED DBG1  // A0
#define I2CLED A1LED   // A1
#define UARTLED A2LED // A2
#define ERRLED DBG0  // DBG0

#elif SENSORS_PIC

#define SENSOR0_PWR LATBbits.LATB2
#define SENSOR1_PWR LATBbits.LATB3
#define SENSOR2_PWR LATBbits.LATB5

#endif
#endif

#if SENSORS_PIC

// Peripheral controls
#define ADC_ON 1
#define TMR0_ON 0
#define TMR1_ON 0
#define UART_ON 1
#define I2C_ON 1

#elif LOCONET_PIC

// Peripheral controls
#define ADC_ON 0
#define TMR0_ON 0
#define TMR1_ON 0
#define UART_ON 1
#define I2C_ON 1

#endif

#endif

